﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace DAL
{
    public class LinkDAL
    {
        private static string BuildAbsolute(string relativeUrl)
        {
            Uri uri = HttpContext.Current.Request.Url;
            string app = HttpContext.Current.Request.ApplicationPath;
            if (!app.EndsWith("/"))
                app += "/";
            relativeUrl = relativeUrl.TrimStart('/');
            return HttpUtility.UrlPathEncode(String.Format("http://{0}:{1}{2}{3}", uri.Host, uri.Port, app, relativeUrl));
        }
        public static string ToTinTuc(string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("TinTuc.aspx?Page=1"));
            else
                return BuildAbsolute(String.Format("TinTuc.aspx?Page={0}", page));
        }
        public static string ToTinTuc()
        {
            return ToTinTuc("1");
        }
        public static string ToTinTucs(string ID)
        {
            return BuildAbsolute(String.Format("EditTinTuc.aspx?IDTinTuc={0}", ID));
        }
        public static string ToTinTucImages(string fileName)
        {
            return BuildAbsolute(String.Format("TinTucImages/{0}", fileName));
        }
        public static string ToChuDe(string Id, string page)
        {
            if (page == "1")

                return BuildAbsolute(String.Format("DMSanPham.aspx?IDChuDe={0}", Id));
            else
                return BuildAbsolute(String.Format("DMSanPham.aspx?IDChuDe={0}&Page{1}", Id, page));
        }
        public static string ToChuDe(string Id)
        {
            return ToChuDe(Id, "1");
        }
        public static string ToLoaiSP(string Id, string page)
        {
            if (page == "1")

                return BuildAbsolute(String.Format("", Id));
            else
                return BuildAbsolute(String.Format("", Id, page));
        }
        public static string ToLoaiSP(string Id)
        {
            return ToLoaiSP(Id, "1");
        }
        public static string ToAdminUpLoad(string clientId, string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("Admins/Upload.aspx?id={0}", clientId));
            else
                return BuildAbsolute(String.Format("Admins/Upload.aspx?id={0}&Page={1}", clientId, page));

        }
        public static string ToAdminUpLoad(string clientId)
        {
            return ToAdminUpLoad(clientId, "1");
        }
        public static string ToAdmin_TinTuc(string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("Admins/TinTuc.aspx?Page=1"));
            else
                return BuildAbsolute(String.Format("Admins/TinTuc.aspx?Page={0}", page));

        }
        public static string ToAdmin_TinTuc()
        {
            return ToAdmin_TinTuc("1");
        }
        public static string ToAdmin_TaiKhoan(string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("~/Admins/TaiKhoan.aspx"));
            else
                return BuildAbsolute(String.Format("~/Admins/TaiKhoan.aspx?Page={0}", page));

        }
        public static string ToAdmin_TaiKhoan()
        {
            return ToAdmin_TinTuc("1");
        }

        //  SAN PHAM
        public static string ToDMSanPham(string page)
        {
            if (page == "1")
                return BuildAbsolute("DMSanPham.aspx");
            else
                return BuildAbsolute(String.Format("DMSanPham.aspx?Page={0}", page));
        }
        public static string ToDMSanPham()
        {
            return ToDMSanPham("1");
        }
        public static string ToHinhAnhSanPham(string filename)
        {
            return BuildAbsolute(String.Format("HinhAnhSanPham/{0}", filename));
        }
        public static string ToSanPham(string Id)
        {
            return BuildAbsolute(String.Format("SanPhams.aspx?IDSP={0}", Id));
        }
        public static string ToGioHang(string Id)
        {
            return BuildAbsolute(String.Format("GioHang.aspx?IDSP={0}", Id));
        }
        public static string ToSearchString(string searchString, string page)
        {
            if (page == "1")
                return BuildAbsolute(String.Format("Admins/SearchTinTuc.aspx?Search={0}", searchString));
            else

                return BuildAbsolute(String.Format("Admins/SearchTinTuc.aspx?Search={0}&Page={1}", searchString, page));
        }
        public static string ToSearchString(string search)
        {
            return ToSearchString(search, "1");
        }
        public static string ToSearchChuDe(string search)
        {
            if (search == "1")
                return BuildAbsolute(String.Format("Admins/SearchChuDe.aspx", search));
            else
                return BuildAbsolute(String.Format("Admins/SearchChuDe.aspx?Search={0}", search));
        }
        public static string ToSearchChuDe()
        {
            return ToSearchChuDe("1");
        }
        public static string ToSearchLoaiSP(string search)
        {
            if (search == "1")
                return BuildAbsolute(String.Format("Admins/SearchLoaiSP.aspx", search));
            else
                return BuildAbsolute(String.Format("Admins/SearchLoaiSP.aspx?Search={0}", search));
        }
        public static string ToSearchLoaiSP()
        {
            return ToSearchLoaiSP("1");
        }
    }
}
